# 读取税率表文件
def read_tax_table(file_path):
    tax_table = []
    with open(file_path, 'r', encoding='utf-8') as file:
        lines = file.readlines()
        for line in lines[1:]:  # 跳过表头
            data = line.strip().split()
            lower = float(data[0])
            upper = float(data[1]) if data[1] != 'inf' else float('inf')
            rate = float(data[2])
            tax_table.append((lower, upper, rate))
    return tax_table


# 计算应缴税额
def calculate_tax(salary, tax_table):
    tax = 0.0
    for lower, upper, rate in tax_table:
        if salary > lower:
            taxable_amount = min(salary, upper) - lower
            tax += taxable_amount * rate
    return tax


# 主程序
def main():
    file_path = "个人税率表.txt"
    tax_table = read_tax_table(file_path)

    try:
        salary = float(input("请输入您的工资收入："))
        if salary < 0:
            print("工资收入不能为负数！")
            return

        tax = calculate_tax(salary, tax_table)
        print(f"应缴税额为：{tax:.2f}元")
    except ValueError:
        print("请输入有效的数字！")


if __name__ == "__main__":
    main()